<?php
include 'mysql.inc.php';
$phone = $_POST['phone'];
$name = $_POST['name'];
$address = $_POST['address'];


session_start();
$user = $_SESSION['user'];
if(!isset($user)) {
	closeConnection();
	exit;
}
$sql = "select * from `user` where id='{$user}'";
$rs = query($sql);
$row = mysql_fetch_assoc($rs);

if ($row['rank'] == 0) {
	closeConnection();
	exit;
}

if ($row['phone'] != $phone || $row['name'] != $name) {
	$result = array("res" => 'fail');
	echo json_encode($result);
	closeConnection();
	exit;
}

$rank = $row['rank'];

$sql = "INSERT IGNORE INTO `record`(`phone`, `name`, `create_time`, `userid`, `address`, `rank`) VALUES('{$phone}', '{$name}', NOW(), '{$user}', '{$address}', '{$rank}')";
query($sql);
$result = array("res" => 'success');
echo json_encode($result);
closeConnection();
?>